<template>
  <div class="blogs">
    <Header></Header>
    <div class="block">
      <el-timeline>
        <!--寻找的是router里面的名称和路由 -->
        <el-timeline-item
          :timestamp="blog.created"
          placement="top"
          v-for="(blog, index) in blogs"
          :key="index"
        >
          <el-card>
            <h4>
              <router-link
                :to="{ name: 'BlogDetail', params: { blogId: blog.id } }"
              >
                {{ blog.title }}
              </router-link>
            </h4>
            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
    <el-pagination
      class="pagination"
      background
      layout="prev, pager, next"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="page"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import Header from "../components/Header";
export default {
  name: "Blogs",
  components: {
    Header,
  },
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 5,
    };
  },
  methods: {
    page(currentPage) {
      console.log(currentPage);
      let that = this;
      this.$axios.get("/blogs?currentPage=" + currentPage).then((res) => {
        console.log(res);
        this.blogs = res.data.data.records;
        this.currentPage = res.data.data.current;
        this.total = res.data.data.total;
      });
    },
  },
  created() {
    this.page(1);
  },
};
</script>

<style>
.blogs {
  max-width: 960px;
  margin: 0 auto;
}
</style>
